package com.chaos.eurekaproducer.juc;

import java.nio.ByteBuffer;

/**
 * @author liaopeng
 * @title: MethodTest
 * @projectName eureka-producer
 * @description: 测试多线程的几个方法：wait、sleep、join、yield
 * @date 2021/10/8下午3:51
 */
public class MethodTest {
    public static void main(String[] args) {
        MyThread thread1 = new MyThread("线程1");
        MyThread thread2 = new MyThread("线程2");
        thread1.start();
        thread2.start();
    }
}

class MyThread extends Thread{
    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            if (getName().equals("线程1")){
                yield();
                System.out.println(getName()+":"+i);
            }
        }
    }
}